package com.glorystone.ins.controller;
import com.glorystone.ins.beanUtils.CharUtils;
import com.glorystone.ins.beanUtils.ExcelUtil;
import com.glorystone.ins.common.common.PageVo;
import com.glorystone.ins.common.util.DateEnum;
import com.glorystone.ins.common.util.DateUtils;
import com.glorystone.ins.vo.*;
import com.glorystone.ins.domain.*;
import com.glorystone.ins.enums.*;
import com.glorystone.ins.interceptor.PageList;
import com.glorystone.ins.service.*;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import com.glorystone.ins.common.JsonResult;
import com.glorystone.ins.common.common.DataTable;
import com.glorystone.ins.common.constants.Constants;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
@Slf4j
@Controller
@RequestMapping("/ins/order")
public class OrderController extends BaseController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private InsurerService insurerService;
    @Autowired
    private ProductSvr productSvr;
    @Autowired
    private CapitalRecordService capitalRecordService;
    @Autowired
    private ChannelService channelService;
    @Autowired
    private AttachmentService attachmentService;
    @Autowired
    private BusinessLogService businessLogService;
    @Autowired
    private ISysUserService sysUserService;
    /**
     * ordNum 保单号 查询条件之一
     * insurant 被保险人 查询条件之一
     * insureStartDate 订单日期 查询条件之一
     * 不输入查询条件，默认按照登录人进行查找
     *
     * @return list 订单列表
     */
    @RequestMapping("/list")
    public ModelAndView toOrderList(HttpServletRequest request) {
        ModelAndView model = new ModelAndView("/order/orderlist");
        /**
         * 保险公司查询
         */
        List<Insurer> insurers = productSvr.getCompany();
        if (insurers != null && insurers.size() > 0) {
            model.addObject("insurerList", insurers);
        }
        /**
         * 订单状态查询
         */
        Map orderStatus = OrderMap.orderStatus;
        model.addObject("orderStatus", orderStatus);
        /**
         * 查询授信状态
         */
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        Channel channel = orderService.findChannel(user);
            if(channel!=null){
                Integer status = channel.getStatus();
                System.out.println("status--------"+status);
                if(status==6){
                    model.addObject("channelstatus",status);
                }
            }
        String createorder = request.getParameter("createorder");
        model.addObject("createorder",createorder);
        return model;
    }

    /**
     * 订单列表数据查询
     * @param request
     * @return 返回订单列表信息
     */
    @ResponseBody
    @RequestMapping("/tolist")
    public DataTable<OrderVo> qureyOrderVoList(HttpServletRequest request) {
        /**
         * 查询条件数据封装
         */
        PageVo vo = parametToPageVo(request, OrderVo.class);
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        int userLevel = user.getUserLevel();
        DataTable data=null;
        if(userLevel==1){
            PageList<OrderVo> orderList = orderService.findOrderVoListAll(vo);
            data = resultToDataTable(orderList);
            return data;
        }
        Channel channel = orderService.findChannel(user);
                    if (channel != null) {
                        Long tid = channel.getTid();
                        if (tid != null) {
                            PageList<OrderVo> orderList = orderService.findOrderVoList(tid, vo);
                            data = resultToDataTable(orderList);
                            return data;
                        }
                    }else {
                        PageList<OrderVo> orderList=null;
                        data = resultToDataTable(orderList);
                        return data;
                    }
        return data;
    }

    /**
     * 订单列表修改
     * @param typeInsurance1 产品类型 封装了公司tid和产品类型
     * @return 返回url，跳转到订单列表
     */
    @RequestMapping("/modify")
    public String modifyOder(Order order, String[] typeInsurance1,Long orderTid) {
        order.setTid(orderTid);
        int status = orderService.insertOrder(order, typeInsurance1);
        if(status>0){
            log.info("订单新建后查询成功");
        }
        if(status==-1){
            log.info("不具备创建订单资格，请办理相关手续");
        }
        if(status==-2){
            log.info("不能进入编辑，前置模式有误，请重新操作");
        }
        if(status==-3){
            log.info("产品不能为空，请重新录入信息");
        }
        return "redirect:/ins/order/list";
    }

    /**
     * 确认定价
     * return 返回model信息
     */
    @RequestMapping("/confirmprice")
    public ModelAndView confirmPrice(String tid) {
        ModelAndView model = new ModelAndView();
        OrderVo orderVo = orderService.findOrderVoByCode(tid);
        if (orderVo != null) {
            model.addObject("orderVo", orderVo);
        }
        model.addObject("orderTid", orderVo.getTid());
        model.addObject("orderCode", tid);
        model.addObject("viewstyle", 80);
        model.setViewName("/order/orderlist");
        return model;
    }

    /**
     * @Param ordercode 订单编号
     * return 返回单条订单信息
     */
    @ResponseBody
    @RequestMapping("/findord")
    public  Map<String,Object> findOrderBycode(String ordercode) {
        Map<String,Object> ordmap=new HashMap<>();
        Order order = orderService.findOrderByCode(ordercode);
        Long productId = order.getProductId();
        Product product = productSvr.getProductByTid(productId);
        List<EaringPoint> earingPointList = product.getEaringPointList();
        ordmap.put("products",earingPointList);
        ordmap.put("data",order);
        return ordmap;
    }

    /**
     * 同意确认定价状态改为待支付
     * @param orderTid
     * @param orderMark
     * @return
     */
    @RequestMapping("/agreePayState")
    public String argeePayState( @RequestParam Long orderTid, @RequestParam String orderMark) {
        Order order = new Order();
        /**
         * 确认定价同意，改为待支付
         */
        order.setTid(orderTid);
        order.setStatus(OrderStatusEnum.TO_PAID.getValue());
        order.setChannelStatus(MainOrderStatusEnum.TO_PAID.getIndex());
        orderService.modifyPayState(order, orderTid, orderMark,FlowOperateTypeEnum.PASS);
        return "redirect:/ins/order/list";
    }
    /**
     * @Param orderCode 订单编号
     * @Param orderTid 订单tid
     * @Param orderMark 确认定价审核信息
     */
    @RequestMapping("/refusePayState")
    public String modifyPatSate(@RequestParam Long orderTid, @RequestParam String orderMark) {
        Order order = new Order();
        /**
         * 确认定价拒绝，改为已拒绝定价
         */
        order.setTid(orderTid);
        order.setChannelStatus(MainOrderStatusEnum.HAS_REFUSE_PRICE.getIndex());
        order.setStatus(OrderStatusEnum.HAS_REFUSED.getValue());
        orderService.modifyPayState(order, orderTid, orderMark,FlowOperateTypeEnum.REJECT);
        return "redirect:/ins/order/list";
    }

    /**
     * 订单列表下载
     */
    @RequestMapping("/export")
    public void exportOrderList(HttpServletRequest request, HttpServletResponse response, @RequestParam String ordNum, @RequestParam String insurant,
                                @RequestParam String insureStartDate, @RequestParam String orderstatus, @RequestParam Integer flag) throws IOException {

        List<OrderVo> orderList = orderService.findOrderVoList(ordNum, insurant, insureStartDate, CharUtils.stringToNumber(orderstatus));
        String fileName = "保险公司对账数据导出 " + DateUtils.dateToStr(new Date(), DateEnum.DATE_BANK_SEQ);
        String excelname = "订单报表导出";
        new ExcelUtil().setJspHeader(request, response,new OrderVo(),orderList, excelname, fileName, flag);
    }

    /**
     * 获取产品信息
     * @insuranid 保险公司编号
     * @return 返回产品列表信息
     */
    @ResponseBody
    @RequestMapping("/prod")
    public List<Product> findLoanPro(Long insuranid) {
        List<Product> products = productSvr.selectProductStatus(insuranid);
        return products;
    }

    /**
     * 获取订单（保单）明细信息
     * @param tid 订单的ID
     * @return 订单信息 附件信息  操作记录
     */
    @RequestMapping("/orderInfoDetail")
    public ModelAndView orderInfoDetail(OrderQueryConditionVo order, ModelAndView model) {
        /**
         * 根据订单Id查询保险订单信息
         */
        Order orderInfo = orderService.selectOrderInfo(order);
        model.addObject("orderInfo", orderInfo);
        /**
         * 根据订单Id查询保险资金流水信息
         */
        List<CapitalRecord> recordList = capitalRecordService.selectOrderCapitalRecord(order);
        if (recordList != null) {
            for (CapitalRecord capitalRecord : recordList) {
                if (TradeTypeEnums.UNSURE.getValue() == capitalRecord.getTradeType()) {
                    model.addObject("unsureRecord", capitalRecord);
                }else if (OpponentEnum.CHANNEL.getValue() == capitalRecord.getOpponent()) {
                    model.addObject("channelRecord", capitalRecord);
                }else if (OpponentEnum.INSURANCECOMPANY.getValue() == capitalRecord.getOpponent()) {
                    model.addObject("companyRecord", capitalRecord);
                }
            }
        }
        model.addObject("tabType",2);
        List<Attachment> orderAttectList = attachmentService.queryAttachList(order.getTid(), Attachment.BusinessTypeEnum.ORDER.getValue());
        if (orderInfo != null) {
            List<Attachment> channelAttectList = attachmentService.queryAttachList(orderInfo.getTid(), Attachment.BusinessTypeEnum.CHANNEL.getValue());
            SysUser saleman = sysUserService.getUserById(orderInfo.getSaleman());
            model.addObject("saleman", saleman);
            orderAttectList.addAll(channelAttectList);
        }
        model.addObject("attachList", orderAttectList);
        List<BusinessLog> optionList = businessLogService.findList(BusinessLog.BusinessTypeEnum.ORDER, order.getTid());
        model.addObject("optionList", optionList);
        model.setViewName("/order/orderInfoDetail");
        return model;
    }

    /**
     *  初始化应付订单列表（渠道和保险公司）
     * @return 所有保险公司信息，订单状态数字字典
     */
    @RequestMapping("/skipOrderList")
    public ModelAndView skipPayOrderView(@RequestParam(value = "tabType",
            required = false,defaultValue = "0") String tabType ,ModelAndView model) {
        List<Insurer> insurerList = insurerService.selectAllInsurer();
        model.addObject("insurerList", insurerList);
        List<Dictionary> payThemeList = getDictionaryListByType(Constants.PAY_THEME);
        model.addObject("payThemeList", payThemeList);
        List<Dictionary> orderStatusList = getDictionaryListByType(Constants.PAY_INSURER_ORDER_STATUS);
        model.addObject("orderStatusList", orderStatusList);
        model.addObject("tabType",tabType);
        model.setViewName("/order/PayOrderlist");
        return model;
    }

    @RequestMapping(value = "toList", method = RequestMethod.GET)
    public String toRemoveOrderView() {
        return "order/removeOrder";
    }

    /**
     * 为应付订单列表查询数据（渠道或者保险公司）
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectOrderList", method = RequestMethod.GET)
    public DataTable selectPayOrderList(HttpServletRequest request) {
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        request.setAttribute("userId", user.getTid());
        PageVo vo = parametToPageVoData(request, OrderQueryConditionVo.class, user);
        PageList<OrderViewVO> orderList = orderService.selectorderList(vo);
        DataTable orderInfo = resultToDataTable(orderList);
        return orderInfo;
    }
    /**
     * 为订单审核查询数据
     * @param request
     * @return
     */
    @RequestMapping("/findOrderCheckInfo")
    public ModelAndView findOrderCheckInfo(OrderQueryConditionVo order, ModelAndView model) {
        /**
         * 根据订单Id查询保险订单信息
         */
        Order orderInfo = orderService.selectOrderInfo(order);
        model.addObject("orderInfo", orderInfo);
//        if (orderInfo != null) {
//            Insurer insurer = insurerService.getInsurerById(orderInfo.getInsyrerId());
//            model.addObject("insurerInfo", insurer);
//        }
        model.addObject("tabType",3);
        List<BusinessLog> optionList = businessLogService.findList(BusinessLog.BusinessTypeEnum.ORDER, order.getTid());
        model.addObject("optionList", optionList);
        List<Dictionary> payThemeList = getDictionaryListByType(Constants.PAY_THEME);
        model.addObject("payThemeList", payThemeList);
        model.setViewName("/order/PayOrderlist");
        return model;
    }

    @ResponseBody
    @RequestMapping("/checkReset")
    public OperateResult orderCheckReset(OrderQueryConditionVo order) {
        OperateResult jsonResult = OperateResult.createErrorMsg("订单审核驳回操作开始");
        jsonResult = orderService.resetOrder(order, jsonResult);
        return jsonResult;
    }
    @ResponseBody
    @RequestMapping("/passOrder")
    public OperateResult orderCheckPass(OrderQueryConditionVo order) {
        OperateResult jsonResult = OperateResult.createErrorMsg("订单审核驳回操作开始");
        jsonResult = orderService.passOrder(order, jsonResult);
        return jsonResult;
    }
    /***********************************************************已结算订单******************************************************************************/
    /**
     * 去已结算订单页
     *
     * @param model
     * @return
     */
    @RequestMapping("/toPrepaidOrderList")
    public String prepaidOrder(Model model) {
        List<Insurer> insurerList = insurerService.selectAllInsurer();
        List<Channel> channelList = channelService.findAll();
        model.addAttribute("insurerList", insurerList);
        model.addAttribute("channelList", channelList);
        return "order/prepaidOrderList";
    }

    /**
     * 查询保险公司已结算订单
     * @param request
     * @return
     */
    @RequestMapping("/getInsyrerData")
    @ResponseBody
    public DataTable<OrderVo> getInsyrerData(HttpServletRequest request){
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        PageVo vo =  parametToPageVoData(request, OrderVo.class,user);
        PageList<OrderVo> list = orderService.getInsyrerData(vo);
        DataTable data = resultToDataTable(list);
        log.info("-----------------结果集data" + data + "-------------------------------");
        return data;
    }

    /**
     * 查询渠道已结算订单
     * @param request
     * @return
     */
    @RequestMapping("/getChannelData")
    @ResponseBody
    public DataTable<OrderVo> getChannelData(HttpServletRequest request){
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        PageVo vo =  parametToPageVoData(request, OrderVo.class,user);
        PageList<OrderVo> list = orderService.getChannelData(vo);
        DataTable data = resultToDataTable(list);
        log.info("-----------------结果集data"+data+"-------------------------------");
        return data;
    }
    @RequestMapping("/perfectOrder")
    public String perfectOrder(Long tid,Model model){
    	OrderQueryConditionVo order = new OrderQueryConditionVo();
    	order.setTid(tid);
    	Order orderInfo = orderService.selectOrderInfo(order);
    	Insurer insurer = insurerService.getInsurerById(orderInfo.getInsyrerId());
        /**
         * 根据订单Id查询保险资金流水信息
         */
        List<CapitalRecord> recordList = capitalRecordService.selectOrderCapitalRecord(order);
        if (recordList != null) {
            for (CapitalRecord capitalRecord : recordList) {
                if (TradeTypeEnums.UNSURE.getValue() == capitalRecord.getTradeType()) {
                    model.addAttribute("unsureRecord", capitalRecord);
                } else if (OpponentEnum.CHANNEL.getValue() == capitalRecord.getOpponent()) {
                    model.addAttribute("channelRecord", capitalRecord);
                } else if (OpponentEnum.INSURANCECOMPANY.getValue() == capitalRecord.getOpponent()) {
                    model.addAttribute("companyRecord", capitalRecord);
                }
            }
        }
        model.addAttribute("tabType",5);
        List<BusinessLog> optionList = businessLogService.findList(BusinessLog.BusinessTypeEnum.ORDER, order.getTid());
        model.addAttribute("optionList", optionList);
        List<Attachment> attachments = attachmentService.queryAttachList(tid, Attachment.BusinessTypeEnum.ORDER.getValue());
        if(attachments!=null && attachments.size()>0){
            Attachment attachment = attachments.get(0);
            model.addAttribute("attachment", attachment);
        }
        List<SysUser> userList = sysUserService.selectByOfficeId((long) 2);
    	model.addAttribute("userList", userList);
    	model.addAttribute("order", orderInfo);
    	model.addAttribute("ordCode", orderInfo.getOrdCode());
    	model.addAttribute("insurer", insurer);
    	return "order/PayOrderlist";
    }
    
    
    @RequestMapping("/updateByOrdCode")
    public @ResponseBody JsonResult updateByOrdCode(Order order){
    	boolean result = orderService.updateByOrdCode(order);
    	if(result){
    		return returnSuccess("操作成功！");
    	}else{
    		return JsonResult.createErrorMsg("操作失败！");
    	}
    }
    /**
     * 下载保险公司
     */
    @RequestMapping("/download")
    public void downloadi(HttpServletRequest request, HttpServletResponse response,
                          String insyrerId,String ordNum,String channelId,String insureStartDate,
                          String insureEndDate,String plateNum){
        if("null".equals(channelId)){
            channelId=null;
        }
        if("null".equals(insyrerId)){
            insyrerId=null;
        }
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        List<OrderVo> orderList = orderService.findAlreadPayCompany(insyrerId,ordNum,channelId,insureStartDate,insureEndDate,plateNum,user);

        String fileName = "已结算保险公司订单导出 " + DateUtils.dateToStr(new Date(), DateEnum.DATE_BANK_SEQ);
        String excelname="已结算保险公司订单报表导出";
        new ExcelUtil().setJspHeader(request,response,new OrderVo(),orderList,excelname,fileName,2);
    }
  /**
     * 下载渠道
     */
    @RequestMapping("/downloadChannel")
    public void download(HttpServletRequest request, HttpServletResponse response,
                          String insyrerId,String ordNum,String channelId,String insureStartDate,
                          String insureEndDate,String plateNum){
        if("null".equals(channelId)){
            channelId=null;
        }
        if("null".equals(insyrerId)){
            insyrerId=null;
        }
        SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
        List<OrderVo> orderList = orderService.findAlreadPayChannel(insyrerId,ordNum,channelId,insureStartDate,insureEndDate,plateNum,user);
        String fileName = "已结算渠道订单导出 " + DateUtils.dateToStr(new Date(), DateEnum.DATE_BANK_SEQ);
        String excelname="已结算渠道订单报表导出";
        new ExcelUtil().setJspHeader(request,response,new OrderVo(),orderList,excelname,fileName,3);
    }
    /**
     * 应付订单下载(渠道)
     */
    @RequestMapping("/channelNeedPay")
    public void channelNeedPay(HttpServletRequest request,HttpServletResponse response,@RequestParam Long insurerId2, @RequestParam String plateNum2,
                                @RequestParam String channelId2,@RequestParam String insurantStartDate,  @RequestParam String  insurantEndDate, @RequestParam int flag) {
        if("undefined".equals(insurantStartDate)){
            insurantStartDate=null;
        }
        if("undefined".equals(insurantEndDate)){
            insurantEndDate=null;
        }
        List<OrderViewVO> orderViewVOS = orderService.dwChannelNeedPay(insurerId2, plateNum2, channelId2,insurantStartDate,insurantEndDate );
        String fileName = "应付订单 " + DateUtils.dateToStr(new Date(), DateEnum.DATE_BANK_SEQ);
        String excelname = "应付订单报表导出(渠道)";
        new ExcelUtil().setJspHeader(request, response,new OrderViewVO(), orderViewVOS, excelname, fileName, flag);
    }
    /**
     * 应付订单下载（保险公司）
     */
    @RequestMapping("/insuranceNeedPay")
    public void insuranceNeedPay(HttpServletRequest request,HttpServletResponse response,@RequestParam Long insurerId1, @RequestParam String plateNum1,
                                @RequestParam String channelId1, int themeKey, @RequestParam int orderStatus, @RequestParam int flag) {
        List<OrderViewVO> orderViewVOS = orderService.downLoadNeedPay(insurerId1, plateNum1, channelId1, themeKey, orderStatus);
        String fileName = "应付订单 " + DateUtils.dateToStr(new Date(), DateEnum.DATE_BANK_SEQ);
        String excelname = "应付订单报表导出(保险公司)";
        new ExcelUtil().setJspHeader(request, response,new OrderViewVO(), orderViewVOS, excelname, fileName, flag);
    }
    /**
     * @param
     * @param
     * @return
     */
    @RequestMapping("/findOrderPayInfo")
    public ModelAndView findOrderPayInfo(OrderQueryConditionVo order, ModelAndView model) {
        /**
         * 根据订单Id查询保险订单信息
         */
        Order orderInfo = orderService.selectOrderInfo(order);
        model.addObject("orderInfo", orderInfo);
        /**
         * 根据订单Id查询保险资金流水信息
         */
        List<CapitalRecord> recordList = capitalRecordService.selectOrderCapitalRecord(order);
        if (recordList != null) {
            for (CapitalRecord capitalRecord : recordList) {

                if (TradeTypeEnums.UNSURE.getValue() == capitalRecord.getTradeType()) {
                    model.addObject("unsureRecord", capitalRecord);
                }else if (OpponentEnum.CHANNEL.getValue() == capitalRecord.getOpponent()) {
                    model.addObject("channelRecord", capitalRecord);
                }else if (OpponentEnum.INSURANCECOMPANY.getValue() == capitalRecord.getOpponent()) {
                    model.addObject("companyRecord", capitalRecord);
                }
            }
        }
        model.addObject("tabType",4);
        List<BusinessLog> optionList = businessLogService.findList(BusinessLog.BusinessTypeEnum.ORDER, order.getTid());
        model.addObject("optionList", optionList);
        model.setViewName("/order/PayOrderlist");
        return model;
    }
    @ResponseBody
    @RequestMapping(value = "/payOperate",method = RequestMethod.POST)
    public OperateResult payOrder(OrderQueryConditionVo order, @RequestParam(required = false) MultipartFile receiptFile){
        order.setFile(receiptFile);
        OperateResult result = OperateResult.createMsg(false, "检查支付条件开始");
        result = orderService.payOrder(order,result);
        return result;
    }
	@ResponseBody
    @RequestMapping(value = "/payChannelOrder",method = RequestMethod.POST)
    public OperateResult payChannelOrder(OrderQueryConditionVo order){
        OperateResult result = OperateResult.createMsg(false, "检查支付条件开始");
        result = orderService.payChannelOrder(order,result);
        return result;
    }
	
	@RequestMapping(value="/onlyOrdNum")
	public @ResponseBody JsonResult onlyOrdNum(String ordNum){
		log.info("传入参数ordNum----------------"+ordNum);
		Order order = orderService.onlyOrdNum(ordNum);
		if(order==null){
            return returnSuccess("保单号可以使用");
        }else{
            return JsonResult.createErrorMsg("该保单号已存在");
        }
	}

    /**
     * 产品不可用，编辑修改产品状态
     * @param orderId 订单tid
     * @param productId  产品id
     */
	@ResponseBody
    @RequestMapping("/modify/productid")
	public  Map<String,Integer> modifyProductIdByOrderId(Long orderId,Long productId){
	    Map<String,Integer> promap= new HashMap<String,Integer>();
        Order order =new Order();
        order.setTid(orderId);
        order.setProductId(productId);
        int i = orderService.modifyProductId(order);
        promap.put("type",i);
        return  promap;
    }
    /**
     * 计算全保费
     */
    @ResponseBody
    @RequestMapping(value = "calcAllPremium",method = RequestMethod.POST)
    public Map<String,BigDecimal> calcAllPremium(@RequestParam(value = "insurance",required = false,defaultValue = "0") BigDecimal insurance,
                                                 @RequestParam(value = "vehicleTexVal",required = false,defaultValue = "0")BigDecimal vehicleTexVal ){
        Map<String,BigDecimal> promap= new HashMap<String,BigDecimal>();
        insurance = insurance.add(vehicleTexVal);
        promap.put("allPremium",insurance);
        return promap;
    }
    /**
     * 计算渠道返佣费
     */
    @ResponseBody
    @RequestMapping(value = "calRebateFee",method = RequestMethod.POST)
    public Map<String,BigDecimal> calRebateFee(@RequestParam(value = "allP",required = false,defaultValue = "0") BigDecimal allP,
                                               @RequestParam(value = "channelPit",required = false,defaultValue = "0")BigDecimal channelPit,
                                               @RequestParam(value = "type",required = false,defaultValue = "0")Integer type){
        Map<String,BigDecimal> promap= new HashMap<String,BigDecimal>();

        BigDecimal calRebateFee = allP.multiply(channelPit).divide(BigDecimal.valueOf(100)).setScale(2,BigDecimal.ROUND_HALF_UP);
        BigDecimal channelMustPay = null;
        BigDecimal channelShowPay = null;
        if(type == 1){
            channelMustPay = allP ;
            channelShowPay = allP ;
        }else if(type == 2){
            channelMustPay = allP.subtract(calRebateFee);
            channelShowPay = allP.subtract(calRebateFee);
        }else if(type == 3){
            channelMustPay = allP.subtract(calRebateFee);
            channelShowPay = BigDecimal.ZERO;
        }
        promap.put("channelRebate",calRebateFee);
        promap.put("channelMustPay",channelMustPay);
        promap.put("channelShowPay",channelShowPay);
        return promap;
    }
    /**
     * 获取渠道返点和税后保费
     * @param rebateSetVo
     * @return
     */
    @RequestMapping(value = "/getRebateAndMoney",method = RequestMethod.POST)
    @ResponseBody
    public OperateResult getRebateAndMoney(RebateSetVo rebateSetVo){
        log.info("--------------------计算渠道返点和税后保费--------------------------");
        OperateResult operateResult = null;
        try {
            operateResult = productSvr.getRebateAndMoney(rebateSetVo);
            if(operateResult==null){
                operateResult = OperateResult.createMsg(false,"计算保费没有返回结果，请联系运维");
            }else{
                operateResult = orderService.resetOrderDirect(operateResult,rebateSetVo.getTid());
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        log.info("--------------------计算结束--------------------------");
        return operateResult;
    }
}